package be.khl.kevinvranken.breekuit;

import be.khl.kevinvranken.breekuit.entiteiten.Blok;
import be.khl.kevinvranken.breekuit.entiteiten.Speelveld;
import java.io.File;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 *
 * @author Kevin
 */
public class maakLevel {

    public static void maak(Spel spel, int level) {
        try {
            InputStream is = maakLevel.class.getResourceAsStream("levels/level" + level + ".xml");
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(is);
            doc.getDocumentElement().normalize();
            NodeList nodeLst = doc.getElementsByTagName("blok");

            spel.setSpeelveld(new Speelveld(spel, doc.getDocumentElement().getAttributes().item(0).getNodeValue()));

            for (int s = 0; s < nodeLst.getLength(); s++) {
                Node node = nodeLst.item(s);
                spel.getEntiteiten().add(new Blok(spel, "sprites/blok_" + node.getFirstChild().getTextContent() + ".gif", Integer.parseInt(node.getAttributes().item(0).getNodeValue()), Integer.parseInt(node.getAttributes().item(1).getNodeValue())));
                spel.resterendeBlokken++;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
